﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:odc="clr-namespace:Odyssey.Controls"
        xmlns:fx="clr-namespace:Odyssey.Effects" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <odc:TwoLineConverter x:Key="twoLineConverter" />
    <odc:TwoLineTextConverter x:Key="twoLineTextConverter" />

    <ControlTemplate x:Key="SmallRibbonDropDownButtonTemplate" TargetType="{x:Type odc:RibbonDropDownButton}">
        <Grid Focusable="False">
            <odc:RibbonChrome x:Name="chrome" Focusable="{TemplateBinding Focusable}" RenderFlat="{TemplateBinding IsFlat}" CornerRadius="{TemplateBinding CornerRadius}"
                    Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}"
                    RenderMouseOver="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" RenderPressed="{TemplateBinding IsDropDownPressed}">
                <odc:RibbonChrome.Content>
                    <DockPanel Margin="2,0,2,0" Focusable="False">
                        <Image Focusable="False" x:Name="image"
                                RenderOptions.BitmapScalingMode="{Binding Path=(odc:ImageRenderOptions.SmallImageScalingMode), RelativeSource={RelativeSource TemplatedParent}}"
                                RenderOptions.EdgeMode="{TemplateBinding EdgeMode}" Source="{TemplateBinding SmallImage}" VerticalAlignment="Center"
                                Margin="0,1,0,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ClipToBounds="True" Width="16"
                                Height="16" DockPanel.Dock="Left"
                                Stretch="{Binding Path=(odc:RibbonButton.ImageStretch), RelativeSource={RelativeSource TemplatedParent}}" />

                        <Image x:Name="symbol" Source="{DynamicResource {ComponentResourceKey odc:Skins, DownArrowImage}}" Margin="1,1,0,0"
                                Focusable="False" Stretch="None" DockPanel.Dock="Right" Width="12" />

                        <ContentControl x:Name="content" Content="{TemplateBinding Content}" VerticalAlignment="Center" Margin="2,0,2,0"
                                Visibility="Visible" Focusable="False" />

                    </DockPanel>
                </odc:RibbonChrome.Content>
            </odc:RibbonChrome>
            <Popup IsOpen="{Binding IsDropDownPressed, RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
                    Placement="{TemplateBinding PopupPlacement}" StaysOpen="True" PopupAnimation="{TemplateBinding PopupAnimation}"
                    MaxHeight="{TemplateBinding MaxDropDownHeight}" AllowsTransparency="True" Name="PART_Popup" Focusable="False">
                <mwt:SystemDropShadowChrome Margin="0,0,5,5" CornerRadius="3" Color="#71000000" Name="Shdw"
                        MinWidth="{TemplateBinding FrameworkElement.ActualWidth}" VerticalAlignment="Stretch">
                    <Border BorderThickness="1,1,1,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                            SnapsToDevicePixels="True" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                            VerticalAlignment="Stretch" Width="{TemplateBinding DropDownWidth}" CornerRadius="0,0,3,3" ClipToBounds="True"
                            Name="DropDownBorder">
                        <Grid ClipToBounds="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ContentPresenter Grid.Row="0" Content="{TemplateBinding DropDownHeader}"
                                    ContentTemplate="{TemplateBinding DropDownHeaderTemplate}" />
                            <ContentPresenter Grid.Row="2" ClipToBounds="True" Content="{TemplateBinding DropDownFooter}"
                                    ContentTemplate="{TemplateBinding DropDownFooterTemplate}" />
                            <Grid Grid.Row="1" SnapsToDevicePixels="True">
                                <Rectangle RadiusX="2" RadiusY="2" Fill="#FFF1F1F1" Width="22" Margin="2,2,2,2" HorizontalAlignment="Left" />
                                <Rectangle Fill="#FFE2E3E3" Width="1" Margin="25,2,0,2" HorizontalAlignment="Left" />
                                <Rectangle Fill="#FFFFFFFF" Width="1" Margin="26,2,0,2" HorizontalAlignment="Left" />
                                <ScrollViewer x:Name="scroller" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True"
                                        HorizontalScrollBarVisibility="Disabled" CanContentScroll="True" Margin="2">
                                    <ItemsPresenter x:Name="PART_Items" Focusable="False" KeyboardNavigation.DirectionalNavigation="Contained"  />
                                </ScrollViewer>
                            </Grid>
                        </Grid>
                    </Border>
                </mwt:SystemDropShadowChrome>
                <Popup.Resources>
                    <Style TargetType="{x:Type odc:RibbonButton}">
                        <Setter Property="odc:RibbonBar.Size" Value="Medium" />
                    </Style>
                </Popup.Resources>
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="False">
                <Setter Property="Visibility" Value="Collapsed" TargetName="scroller" />
            </Trigger>
            <Trigger Property="IsOpen" Value="True" SourceName="PART_Popup">
                <Setter Property="RenderPressed" Value="True" TargetName="chrome" />
            </Trigger>
            <Trigger Property="odc:RibbonBar.Size" Value="Small">
                <Setter Property="Visibility" Value="Collapsed" TargetName="content" />
                <Setter Property="Width" Value="0" TargetName="content" />
            </Trigger>
            <Trigger Property="ShowDropDownSymbol" Value="False">
                <Setter Property="Visibility" Value="Collapsed" TargetName="symbol" />
            </Trigger>
            <Trigger Property="odc:RibbonBar.Size" Value="Minimized">
                <Setter Property="Visibility" Value="Collapsed" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsEnabled" Value="False" />
                    <Condition Property="odc:RibbonChrome.IsGrayScaleEnabled" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="RenderOptions.EdgeMode" Value="Unspecified" TargetName="image" />
                <Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" TargetName="image" />
                <Setter Property="Opacity" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledImageOpacity}}" TargetName="image" />
                <Setter Property="Effect" TargetName="image">
                    <Setter.Value>
                        <fx:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledForegroundBrush}}" />
            </Trigger>
            <Trigger Property="IsDropDownPressed" Value="True">
                <!--Don't open the tooltip when the popup is open:-->
                <Setter Property="ToolTip" Value="{x:Null}" />
            </Trigger>
        </ControlTemplate.Triggers>
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type odc:RibbonButton}">
                <Setter Property="odc:RibbonBar.Size" Value="Medium" />
                <Setter Property="Template" Value="{DynamicResource RibbonButtonSmallControlTemplate}" />
            </Style>
        </ControlTemplate.Resources>
    </ControlTemplate>

    <ControlTemplate x:Key="LargeRibbonDropDownButtonTemplate" TargetType="{x:Type odc:RibbonDropDownButton}">
        <odc:RibbonChrome MouseOverBackground="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedDropDownBg}}" Focusable="False"
                CornerRadius="{TemplateBinding CornerRadius}" VerticalContentAlignment="Stretch" RenderFlat="{TemplateBinding IsFlat}"
                BorderBrush="{TemplateBinding BorderBrush}" HorizontalContentAlignment="Stretch" Background="{TemplateBinding Background}"
                RenderMouseOver="{TemplateBinding IsMouseOver}">
            <odc:RibbonChrome x:Name="chrome" Margin="-2" HorizontalContentAlignment="Center" Focusable="False" VerticalContentAlignment="Top"
                    CornerRadius="{TemplateBinding CornerRadius}" RenderMouseOver="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
                    RenderPressed="{TemplateBinding IsDropDownPressed}">
                <odc:RibbonChrome.Content>
                    <Grid Height="72" Margin="2,-2,2,-2" Focusable="False">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="44" />
                            <RowDefinition Height="4" />
                            <RowDefinition Height="12" />
                            <RowDefinition Height="12" />
                        </Grid.RowDefinitions>

                        <Image x:Name="image"
                                RenderOptions.BitmapScalingMode="{Binding Path=(odc:ImageRenderOptions.LargeImageScalingMode), RelativeSource={RelativeSource TemplatedParent}}"
                                RenderOptions.EdgeMode="Aliased" SnapsToDevicePixels="False" Source="{TemplateBinding LargeImage}"
                                VerticalAlignment="Center" HorizontalAlignment="Center" Width="32" Height="32" Grid.Row="0"
                                Stretch="{Binding Path=(odc:RibbonButton.ImageStretch), RelativeSource={RelativeSource TemplatedParent}}" />

                        <TextBlock Grid.Row="2"
                                Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource twoLineTextConverter},ConverterParameter=1}"
                                VerticalAlignment="Bottom" HorizontalAlignment="Center" />

                        <StackPanel Orientation="Horizontal" Grid.Row="3" HorizontalAlignment="Center">

                            <TextBlock
                                    Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource twoLineTextConverter},ConverterParameter=2}"
                                    VerticalAlignment="Bottom" HorizontalAlignment="Center" />

                            <Image x:Name="symbol" Source="{DynamicResource {ComponentResourceKey odc:Skins, DownArrowImage}}" Margin="3,0,2,0"
                                    Stretch="None" />
                        </StackPanel>

                        <Popup Placement="Bottom" StaysOpen="True" MaxHeight="{TemplateBinding MaxDropDownHeight}"
                                PopupAnimation="{TemplateBinding PopupAnimation}"
                                PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}" AllowsTransparency="True"
                                Name="PART_Popup" Focusable="False">
                            <mwt:SystemDropShadowChrome Margin="0,0,5,5" Color="#71000000" Name="Shdw2" CornerRadius="3" Focusable="False"
                                    MinWidth="{TemplateBinding FrameworkElement.ActualWidth}">
                                <Border Width="{TemplateBinding DropDownWidth}" CornerRadius="0,0,3,3" BorderThickness="1,1,1,1"
                                        SnapsToDevicePixels="True" Focusable="False"
                                        BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                                        Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Name="DropDownBorder">
                                    <Grid ClipToBounds="True" Focusable="False">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="*" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <ContentPresenter Grid.Row="0" Content="{TemplateBinding DropDownHeader}" Focusable="False"
                                                ContentTemplate="{TemplateBinding DropDownHeaderTemplate}" />
                                        <ContentPresenter Grid.Row="2" ClipToBounds="True" Content="{TemplateBinding DropDownFooter}"
                                                Focusable="False" ContentTemplate="{TemplateBinding DropDownFooterTemplate}" />
                                        <Grid Grid.Row="1" SnapsToDevicePixels="True">
                                            <Rectangle RadiusX="2" RadiusY="2" Fill="#FFF1F1F1" Width="22" Margin="2,2,2,2" HorizontalAlignment="Left" />
                                            <Rectangle Fill="#FFE2E3E3" Width="1" Margin="25,2,0,2" HorizontalAlignment="Left" />
                                            <Rectangle Fill="#FFFFFFFF" Width="1" Margin="26,2,0,2" HorizontalAlignment="Left" />
                                            <ScrollViewer x:Name="scroller" VerticalScrollBarVisibility="Auto" SnapsToDevicePixels="True"
                                                    HorizontalScrollBarVisibility="Disabled" CanContentScroll="True" Margin="2">
                                                <ItemsPresenter x:Name="PART_Items" Focusable="False" KeyboardNavigation.DirectionalNavigation="Contained" />
                                            </ScrollViewer>
                                        </Grid>
                                    </Grid>

                                </Border>
                            </mwt:SystemDropShadowChrome>
                        </Popup>

                    </Grid>
                </odc:RibbonChrome.Content>
            </odc:RibbonChrome>
        </odc:RibbonChrome>
        <ControlTemplate.Triggers>
            <Trigger Property="HasItems" Value="False">
                <Setter Property="Visibility" Value="Collapsed" TargetName="scroller" />
            </Trigger>
            <Trigger Property="ShowDropDownSymbol" Value="False">
                <Setter Property="Visibility" Value="Collapsed" TargetName="symbol" />
            </Trigger>
            <Trigger Property="odc:RibbonBar.Size" Value="Minimized">
                <Setter Property="Visibility" Value="Collapsed" />
            </Trigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsEnabled" Value="False" />
                    <Condition Property="odc:RibbonChrome.IsGrayScaleEnabled" Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="RenderOptions.EdgeMode" Value="Unspecified" TargetName="image" />
                <Setter Property="RenderOptions.BitmapScalingMode" Value="Fant" TargetName="image" />
                <Setter Property="Opacity" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledImageOpacity}}" TargetName="image" />
                <Setter Property="Effect" TargetName="image">
                    <Setter.Value>
                        <fx:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </MultiTrigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Foreground" Value="{DynamicResource {ComponentResourceKey odc:Skins, DisabledForegroundBrush}}" />
            </Trigger>
            <Trigger Property="IsDropDownPressed" Value="True">
                <!--Don't open the tooltip when the popup is open:-->
                <Setter Property="ToolTip" Value="{x:Null}" />
            </Trigger>
        </ControlTemplate.Triggers>
        <ControlTemplate.Resources>
            <Style TargetType="{x:Type odc:RibbonButton}">
                <Setter Property="odc:RibbonBar.Size" Value="Medium" />
                <Setter Property="Template" Value="{DynamicResource RibbonButtonSmallControlTemplate}" />
            </Style>
        </ControlTemplate.Resources>

    </ControlTemplate>

    <Style TargetType="{x:Type odc:RibbonDropDownButton}">
        <Setter Property="BorderBrush" Value="{DynamicResource {ComponentResourceKey odc:Skins, HighlightedRibbonBorderBrush}}" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="odc:RibbonChrome.AnimateTransition"
                Value="{Binding Path=(odc:RibbonOption.AnimateTransition), RelativeSource={RelativeSource Self}}" />
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template" Value="{StaticResource SmallRibbonDropDownButtonTemplate}" />
        <Style.Triggers>
            <Trigger Property="odc:RibbonBar.Size" Value="Large">
                <Setter Property="Template" Value="{StaticResource LargeRibbonDropDownButtonTemplate}" />
                <Setter Property="Height" Value="72" />
            </Trigger>
        </Style.Triggers>
    </Style>
</ResourceDictionary>